package top.leyi.exception;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Allen
 * @date 2019/4/19
 * @desc 权限异常类
 */

@ControllerAdvice
public class ExceptionHandle {

    @ExceptionHandler({TokenException.class})
    @ResponseBody
    public Map<String, String> exceptionHandle(Exception e){
        Map<String, String> map = new HashMap<>();
        map.put("code", "401");
        map.put("msg", "token过期");
        return map;
    }

    @ExceptionHandler({NoSuchAuthException.class})
    @ResponseBody
    public Map<String, String> noSuchAuthExceptionHandle(Exception e){
        Map<String, String> map = new HashMap<>();
        map.put("code", "401");
        map.put("msg", "缺少权限");
        return map;
    }

    @ExceptionHandler({NotSuchUserIdException.class})
    @ResponseBody
    public Map<String, String> notSuchUserIdException(Exception e){
        Map<String, String> map = new HashMap<>();
        map.put("code", "401");
        map.put("msg", "id或token错误");
        return map;
    }

    @ExceptionHandler({TalkNotFoundException.class})
    @ResponseBody
    public Map<String, String> talkNotFoundException(Exception e){
        Map<String, String> map = new HashMap<>();
        map.put("code", "404");
        map.put("msg", "无效的talkId");
        return map;
    }

    @ExceptionHandler({NoSuchClassException.class})
    @ResponseBody
    public Map<String, String> noSuchClassExceptionHandle(Exception e){
        Map<String, String> map = new HashMap<>();
        map.put("code", "404");
        map.put("msg", "没有这个班级");
        return map;
    }

//    @ExceptionHandler({Exception.class})
//    @ResponseBody
//    public Map<String, String> noIdeaException(Exception e){
//        e.printStackTrace();
//        Map<String, String> map = new HashMap<>();
//        map.put("code", "500");
//        map.put("msg", "服务端未知错误，请记录下操作并并联系后台人员");
//        return map;
//    }

}
